﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SixApp.Core;
using SixApp.Entities;
using SixApp.Repositories;

namespace SixApp
{
    public partial class FormHistoryDetail : BaseForm
    {
        private HistoryRepository mHistoryRepository = new HistoryRepository();

        public FormHistoryDetail()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            int historyId = Convert.ToInt32(this.Tag);

            string nianFen = tbNianFen.Text.Trim();
            string qiShu = tbQiShu.Text.Trim();
            
            int pinYi = Convert.ToInt32(tbPinYi.Text);
            int pinEr = Convert.ToInt32(tbPinEr.Text);
            int pinSan = Convert.ToInt32(tbPinSan.Text);
            int pinShi = Convert.ToInt32(tbPinShi.Text);
            int pinWu = Convert.ToInt32(tbPinWu.Text);
            int pinLiu = Convert.ToInt32(tbPinLiu.Text);
            int teMa = Convert.ToInt32(tbTeMa.Text);

            string shengXiao = tbShengXiao.Text.Trim();
            string boLu = tbBoLu.Text.Trim();
            string danShuang = tbDanShuang.Text.Trim();
            string wuHang = tbWuHang.Text.Trim();
            string jiaYe = tbJiaYe.Text.Trim();
            string daXiao = tbDaXiao.Text.Trim();

            int teTou = Convert.ToInt32(tbTeTou.Text);
            int weiShu = Convert.ToInt32(tbWeiShu.Text);
            int menShu = Convert.ToInt32(tbMenShu.Text);
            int duanWei = Convert.ToInt32(tbDuanWei.Text);

            string tmfw = tbTmfw.Text.Trim();

            int hds = Convert.ToInt32(tbHds.Text);
            int zhds = Convert.ToInt32(tbZhds.Text);

            History history = new History() { 
                Id = historyId,
                nianfen = nianFen,
                qishu = qiShu,
                pinyi = pinYi,
                piner = pinEr,
                pinsan = pinSan,
                pinshi = pinShi,
                pinwu = pinWu,
                pinliu = pinLiu,
                tema = teMa,
                shengxiao = shengXiao,
                bolu = boLu,
                dangshuang = danShuang,
                wuhang = wuHang,
                jiaye = jiaYe,
                daxiao = daXiao,
                tetou = teTou,
                weishu = weiShu,
                menshu = menShu,
                duanwei = duanWei,
                tmfw = tmfw,
                hds = hds,
                zhds = zhds
            };

            mHistoryRepository.SaveOrUpdate(history);

            ((FormHistory)this.Owner).BindHistories();
            this.Close();
        }

        private void FormHistoryDetail_Load(object sender, EventArgs e)
        {
            int historyId = (int)this.Tag;
            if (historyId > 0)
            {
                FormHistory formHistory = (FormHistory)this.Owner;
                this.tbNianFen.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colNianFen"].Value);
                this.tbQiShu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colQiShu"].Value);
                this.tbPinYi.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinYi"].Value);
                this.tbPinEr.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinEr"].Value);
                this.tbPinSan.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinSan"].Value);
                this.tbPinShi.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinShi"].Value);
                this.tbPinWu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinWu"].Value);
                this.tbPinLiu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colPinLiu"].Value);
                this.tbTeMa.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colTeMa"].Value);
                this.tbShengXiao.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colShengXiao"].Value);
                this.tbBoLu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colBoLu"].Value);
                this.tbDanShuang.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colDanShuang"].Value);
                this.tbWuHang.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colWuHang"].Value);
                this.tbJiaYe.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colJiaYe"].Value);
                this.tbDaXiao.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colDaXiao"].Value);
                this.tbTeTou.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colTeTou"].Value);
                this.tbWeiShu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colWeiShu"].Value);
                this.tbMenShu.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colMenShu"].Value);
                this.tbDuanWei.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colDuanWei"].Value);
                this.tbTmfw.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colTmfw"].Value);
                this.tbHds.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colHds"].Value);
                this.tbZhds.Text = Convert.ToString(formHistory.HistoryCurrentRow.Cells["colZhds"].Value);
            }
        }

    }
}
